package com.newgoldcurrency.activities;

import android.os.Bundle;
import android.os.Handler;

import androidx.appcompat.app.AppCompatActivity;

import com.newgoldcurrency.databinding.ActivityCountDownBinding;
import com.newgoldcurrency.utils.Tools;

public class CountDownActivity extends AppCompatActivity {
    private ActivityCountDownBinding binding;
    private int seconds=0;
    Handler handler=new Handler();
    Runnable runnable=new Runnable() {
        @Override
        public void run() {
            seconds=seconds-1000;
            if (binding!=null)binding.timeShowcase.setText(Tools.stringForTime(seconds));
            handler.postDelayed(this,1000);
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding= ActivityCountDownBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.countDownBack.setOnClickListener(v -> finish());
        binding.countDownOkBack.setOnClickListener(v->finish());
        seconds=Integer.parseInt(getIntent().getStringExtra("countDown"));
        handler.postDelayed(runnable,0);
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacks(runnable);
        binding=null;
    }
}